package com.example.mobile2021606127cxz0323homework;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    public void initView() {
        EditText edtTxt_username = findViewById(R.id.edtTxt_main_username);
        EditText edtTxt_psw = findViewById(R.id.edtTxt_main_psw);
        Button btn_login = findViewById(R.id.btn_main_login);
        TextView tv_newzhuce=findViewById(R.id.tv_main_newzhuce);
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String text = ((EditText) findViewById(R.id.edtTxt_main_username)).getText().toString().trim();
                String text2 = ((EditText) findViewById(R.id.edtTxt_main_psw)).getText().toString().trim();
                Log.e("星辰", "获取到的账号为: " + text);
                Log.e("星辰", "获取到的密码为: " + text2);
                if (text.length() == 0 | text2.length() == 0) {
                    Toast.makeText(MainActivity2.this, "用户名和密码不能为空", Toast.LENGTH_SHORT).show();
                } else if (6 > text.length()) {
                    Toast.makeText(MainActivity2.this, "用户名长度应在6-10字之间", Toast.LENGTH_SHORT).show();
                } else if (text.length() > 10) {
                    Toast.makeText(MainActivity2.this, "用户名长度应在6-10字之间", Toast.LENGTH_SHORT).show();
                } else if (text.equals("2021606127") && text2.equals("10010")) {
                    Toast.makeText(MainActivity2.this, "登录成功", Toast.LENGTH_LONG).show();
                } else if (text.length() != 0 && text2.length() != 0) {
                    Toast.makeText(MainActivity2.this, "账号或密码错误，请重新输入", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }

    public void startActivity3(View view) {
        startActivity(new Intent(this,MainActivity3.class));
    }
}
